package com.gxa.modules.service.lx.impl;

import com.gxa.common.constant.PageInfo;
import com.gxa.common.vo.R2;
import com.gxa.modules.mapper.lx.OrderActivistMapper;
import com.gxa.modules.mapper.lx.OrderManageMapper;
import com.gxa.modules.service.lx.OrderActivistService;
import com.gxa.modules.service.lx.OrderManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;

@Service
public class OrderActivistServiceImpl implements OrderActivistService {

    @Autowired(required = false)
    private OrderActivistMapper orderActivistMapper  ;

    @Override
    public R2 queryActivistOrderList(Map map) {

        if(map.get("nowPage") == null && map.get("pageSize") == null){
            map.put("nowPage", PageInfo.NOWPAGE);
            map.put("pageSize",PageInfo.PAGESIZE);
        }
        Integer nowPage = ((Integer) map.get("nowPage")-1)*(Integer)map.get("pageSize");
        map.put("nowPage",nowPage);
        Integer sumPage = orderActivistMapper.sumPage(map);
        List<Map> orderlist = orderActivistMapper.queryActivistOrderList(map);
        List list = new ArrayList();
        list.add(sumPage);
        list.add(orderlist);
        R2 r2 = new R2();
        if(list != null){
            r2.setCode(200);
            r2.setMsg("查询成功");
            r2.setData(list);
        }else{
            r2.setCode(500);
            r2.setMsg("系统开小差了");
        }
        return r2;
    }

    @Override
    public R2 queryActivistInfo(Map map) {

        Set orderidlist = orderActivistMapper.queryOrderIdList(map);
        Set goodsnamelist = orderActivistMapper.queryOrderGoodsNameList(map);
        Set vipnamelist = orderActivistMapper.queryOrderVipNameList(map);

        List list = new ArrayList();
        list.add(orderidlist);
        list.add(goodsnamelist);
        list.add(vipnamelist);
        R2 r2 = new R2();
        if(list != null){
            r2.setCode(200);
            r2.setMsg("查询成功");
            r2.setData(list);
        }else{
            r2.setCode(500);
            r2.setMsg("系统开小差了");
        }
        return r2;
    }



    @Override
    public R2 activistChange(Map map) {
        R2 r2 = new R2();
        Integer result = orderActivistMapper.activist(map);
        Integer result1 = orderActivistMapper.changeUserMoney(map);
        Integer result2 = orderActivistMapper.changeShopGoods(map);
        if(result != 0 && result1 != 0 && result2 != 0){
            r2.setCode(200);
            r2.setMsg("修改成功");
        }else{
            r2.setCode(500);
            r2.setMsg("系统开小差了");
        }
        return r2;
    }


}
